import { PageHeaderWrapper } from '@ant-design/pro-layout';
import type { ActionType, ProColumns } from '@ant-design/pro-table';
import ProTable from '@ant-design/pro-table';
import type { SorterResult } from 'antd/es/table/interface';
import React, { useRef, useState } from 'react';
import { querySpaceIncomeStatisticsDataList } from './service';
import type { SpaceIncomeStatisticsData } from './data';
// import { history } from 'umi';

const TableList: React.FC = () => {
  const [sorter, setSorter] = useState<string>('');
  const actionRef = useRef<ActionType>();

  // const showIncomeHistory = (record: SpaceIncomeStatisticsData) => {
  //   const { id } = record;
  //   history.push(`/finance/space-income-statistics/income-history?id=${id}`);
  // };

  const columns: ProColumns<SpaceIncomeStatisticsData>[] = [
    {
      title: '订单编号',
      dataIndex: 'spaceName',
    },
    {
      title: '商家订单号',
      dataIndex: 'latestDate',
    },
    {
      title: '付款方式',
      dataIndex: 'availableProfit',
      hideInSearch: true,
    },
    {
      title: '交易时间',
      dataIndex: 'availableProfit',
      hideInSearch: true,
    },
    {
      title: '收入',
      dataIndex: 'availableProfit',
      hideInSearch: true,
    },
    {
      title: '退款',
      dataIndex: 'availableProfit',
      hideInSearch: true,
    },
    {
      title: '手续费',
      dataIndex: 'availableProfit',
      hideInSearch: true,
    },
    {
      title: '实际到账金额',
      dataIndex: 'availableProfit',
      hideInSearch: true,
    },
    {
      title: '操作',
      dataIndex: 'option',
      hideInSearch: true,
      // render: (_, record) => {
      //   return (
      //     <div>
      //       <a onClick={() => showIncomeHistory(record)}>退款</a>
      //     </div>
      //   );
      // },
    },
  ];

  return (
    <PageHeaderWrapper>
      <ProTable<SpaceIncomeStatisticsData>
        actionRef={actionRef}
        rowKey="id"
        onChange={(_, _filter, _sorter) => {
          const sorterResult = _sorter as SorterResult<SpaceIncomeStatisticsData>;
          if (sorterResult.field) {
            setSorter(`${sorterResult.field}_${sorterResult.order}`);
          }
        }}
        params={{
          sorter,
        }}
        tableAlertRender={() => false}
        request={(params = {}) => {
          console.log('params: ', params);
          const { current: page, pageSize, ...filter } = params;
          return querySpaceIncomeStatisticsDataList({ page, pageSize, ...filter });
        }}
        columns={columns}
        rowSelection={false}
      />
    </PageHeaderWrapper>
  );
};

export default TableList;
